package com.chaoxin.lovehelp.controller;

import java.text.ParseException;
import java.util.Arrays;
import java.util.Map;

import com.chaoxin.lovehelp.common.enums.vo.allNeedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.chaoxin.lovehelp.entity.NeedEntity;
import com.chaoxin.lovehelp.service.NeedService;
import com.chaoxin.lovehelp.common.utils.PageUtils;
import com.chaoxin.lovehelp.common.utils.R;

import javax.servlet.http.HttpServletRequest;


/**
 * 
 *
 * @author honghu
 * @email 3027708213@qq.com
 * @date 2024-02-04 22:13:14
 */
@RestController
@CrossOrigin
@RequestMapping("lovehelp/need")
public class NeedController {
    @Autowired
    private NeedService needService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(HttpServletRequest request, @RequestParam Map<String, Object> params) throws ParseException {
        PageUtils page = needService.queryPage(request,params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		allNeedVo vo  = needService.getNeedVo(id);

        return R.ok().put("need", vo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody NeedEntity need){
        need.setIsDisplay(1);
		needService.save(need);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody NeedEntity need){
		needService.updateById(need);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		needService.removeIds(Arrays.asList(ids));

        return R.ok();
    }

}
